import React,{useEffect, useState} from 'react'
type Props = {
  show: boolean
  lazyRender: boolean
  children?: any
  duration?:number
}
const LazyRender = ({ show, children, lazyRender, ...rest }: Props) => {
  const [_c, set_c] = useState<any>(children)
  const durationTime = () => {
    if (show) {
      set_c(children)
      const tt = setTimeout(() => {
        set_c(null)
        clearTimeout(tt)
      }, rest.duration)
    }
  }
  useEffect(()=>{
    durationTime()
  },[show])
  return (
    <>
      {
        lazyRender ? (show ? children : _c) : children
      }
    </>
  )
}

export default LazyRender